package com.zhx.sweet.handler;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.common.OAuth2AccessToken;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author zhanghaixuan
 * @create 2018/4/24-上午11:28
 **/
public class DefaultCuestomAuthentionSuccessHandler implements CuestomAuthentionSuccessHandler {

    //spring 启动的时候自动注册的一个mapper 可以转换类
    @Autowired
    private ObjectMapper objectMapper;

    @Override
    public void onAuthenticationSuccess(OAuth2AccessToken accessToken, HttpServletRequest request, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException {
        httpServletResponse.setContentType("application/json,charset=UTF-8");
        httpServletResponse.getWriter().write(objectMapper.writeValueAsString(accessToken));
    }

}
